package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Slf4j
@Configuration
public class RedisConfiguration {

    /**
     * 初始化Redis配置
     *
     * @return RedisTemplate 返回配置好的Redis模板对象，可用于执行Redis操作
     */
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        log.info("RedisConfiguration初始化");
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(redisConnectionFactory); // 设置Redis连接工厂
        redisTemplate.setKeySerializer(new StringRedisSerializer()); // 设置键的序列化方式为String
        return redisTemplate;
    }
}
